﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using QuanLyDuAn.BUS;
using QuanLyDuAn.Report;
using System.Collections;

namespace QuanLyDuAn.GUI
{
    public partial class FrmSearchInterviewResult : DevComponents.DotNetBar.Office2007RibbonForm
    {
        public String value;
        InterviewResultController Result = new InterviewResultController();
        InterviewerController interviewer = new InterviewerController();
        ApplicantController applicant = new ApplicantController();
        DataSet ds;
        ArrayList list;
        public FrmSearchInterviewResult()
        {
            InitializeComponent();
        }

        private void FrmSearchInterviewResult_Load(object sender, EventArgs e)
        {
            this.dataGridViewX1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            cmbCriterion.Items.Add("Applicant Name");
            cmbCriterion.Items.Add("Result");
            cmbResult.Items.Add("Reached");
            cmbResult.Items.Add("Not Reached");
            LoadDataToCollection();
            ds= new DataSet();
            ds = applicant.LoadApplicant();
            cmbApplicantname.DataSource = ds.Tables[0];
            cmbApplicantname.DisplayMember = ds.Tables[0].Columns[3].ToString();
            cmbApplicantname.ValueMember = ds.Tables[0].Columns[0].ToString();
            cmbApplicantname.Enabled = false;
            cmbResult.Enabled = false;
        }
        public void CriterionChange()
        {
            String criterion = cmbCriterion.SelectedItem.ToString();
            if (criterion.CompareTo("Applicant Name") == 0)
            {
                MessageBox.Show("Please Select Applicantname !");
                cmbApplicantname.Enabled = true;
                cmbResult.Enabled = false;
            }
            else  
            {
                MessageBox.Show("Please Select Result !");
                cmbApplicantname.Enabled = false;
                cmbResult.Enabled = true;
            }   
        }

        public void LoadDataToCollection()
        {
            AutoCompleteStringCollection autoString = new AutoCompleteStringCollection();
            list = applicant.GetApplicantName();
            foreach (String Name in list)
            {
                autoString.Add(Name);
            }
            cmbApplicantname.AutoCompleteMode = AutoCompleteMode.Append;
            cmbApplicantname.AutoCompleteSource = AutoCompleteSource.CustomSource;
            cmbApplicantname.AutoCompleteCustomSource = autoString;
        }
        public int ValueCriterrion()
        {
            int selection;
            String criter = cmbCriterion.Text;
            if (criter.CompareTo("") != 0)
            {
                String criterion = cmbCriterion.SelectedItem.ToString();
                if (criterion.CompareTo("Applicant Name") == 0)
                {
                    selection = 1;
                }
                else
                {
                    selection = 2;
                }
            }
            else
            {
                selection = 0;
                MessageBox.Show("Please select Criterion! ");
            }
            return selection;
        }
        public void SearchByResult()
        {
            String result = cmbResult.Text;
            if (result.CompareTo("") != 0)
            {
                String resultName = cmbResult.SelectedItem.ToString();
                ds = new DataSet();
                ds = Result.SearchInterviewerByResult(resultName);
                dataGridViewX1.DataSource = ds.Tables[0];
            }
            else
            {
                MessageBox.Show("Please select Type of Result! ");
            }
        }
        public void SearchByApplicant()
        {
            String Name = cmbApplicantname.SelectedValue.ToString();
            ds = new DataSet();
            ds = Result.SearchInterviewerByApplicant(Name);
            dataGridViewX1.DataSource = ds.Tables[0];
        }

        private void cmbCriterion_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.CriterionChange();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            int i = this.ValueCriterrion();
            if (i == 2)
            {
                this.SearchByResult();
            }
            else if(i==1)
            {
                this.SearchByApplicant();
            }
        }

        private void btnPreview_Click(object sender, EventArgs e)
        {
            int i = this.ValueCriterrion();
                
                

                if (i == 2)
                {
                    String result = cmbResult.SelectedItem.ToString();
                    FrmInterviewResultSearch frm = new FrmInterviewResultSearch();
                    frm.value = result;
                    frm.Visible = true;
                    frm.Show();
                }
                else if (i == 1)
                {
                    String applicant = cmbApplicantname.SelectedValue.ToString();
                    FrmInterviewResultApplicant frm = new FrmInterviewResultApplicant();
                    frm.value = applicant;
                    frm.Show();
                }
            }
        }

    }
